# Maintainer: Rafał Brzegowy <rafal.brzegowy@yahoo.com>

_realname=libexodus
_realname2=seacas
_releases=2021-05-12
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=8.11
pkgrel=2
pkgdesc="EXODUS is a model developed to store and retrieve data for finite element analyses (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
conflicts=("${MINGW_PACKAGE_PREFIX}-seacas"
           "${MINGW_PACKAGE_PREFIX}-trilinos")
depends=("${MINGW_PACKAGE_PREFIX}-crt")
makedepends=("unzip"
             "${MINGW_PACKAGE_PREFIX}-netcdf"
             "${MINGW_PACKAGE_PREFIX}-cc"
	     "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
url="https://gsjaardema.github.io/seacas/"
license=('BSD')
source=("https://github.com/gsjaardema/seacas/archive/v${_releases}.zip")
sha256sums=('818F9EFF35A4FAE682CF3B81897D49736C332CB3549AE2B2FC22678B21EE06EE')
noextract=("v${_releases}.zip") # bsdtar could not unpack this archive

prepare() {  
  rm -rf "${srcdir}/seacas-${_releases}"
  unzip -oq v${_releases}.zip -d ${srcdir}
  cd ${_realname2}-${_releases}
  sed -i 's:-pedantic:/:g' cmake-exodus

}

build() {
  [[ -d "${_realname2}-${_releases}/build-${MINGW_CHOST}" ]] && rm -rf "${_realname2}-${_releases}/build-${MINGW_CHOST}"
  mkdir -p "${_realname2}-${_releases}/build-${MINGW_CHOST}" && cd "${_realname2}-${_releases}/build-${MINGW_CHOST}"
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
      INSTALL_PATH=${MINGW_PREFIX} THREADSAFE=ON ../cmake-exodus \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${_realname2}-${_releases}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 "${srcdir}/seacas-${_releases}/packages/seacas/libraries/exodus"/COPYRIGHT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
